package hungarianAlgorithm;

public class AssignmentProblem {

    private final float[][] costMatrix;

    public AssignmentProblem(float[][] aCostMatrix) {
        costMatrix = aCostMatrix;
    }

    private float[][] copyOfMatrix() {
        // make a copy of the passed array
        float[][] retval = new float[costMatrix.length][];
        for (int i = 0; i < costMatrix.length; i++) {
            retval[i] = new float[costMatrix[i].length];
            System.arraycopy(costMatrix[i], 0, retval[i], 0, costMatrix[i].length);
        }
        return retval;
    }

    public int[][] solve() {
        float[][] costMatrix = copyOfMatrix();
        HungarianAlgorithm ha = new HungarianAlgorithm();
        return ha.computeAssignments(costMatrix);
    }
}
